package com.uzhie.web.controller.http;

import com.alibaba.fastjson.JSONObject;
import com.uzhie.web.anno.Auth;
import com.uzhie.web.bean.PageBean;
import com.uzhie.web.bean.PayloadBean;
import com.uzhie.web.controller.http.comm.CommController;
import com.uzhie.web.service.JT_8702Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * Created by Zhangdequan on 2018/7/18.
 */
@RestController
@RequestMapping(value = "JT8702")
public class JT8702Controller extends CommController {

    @Autowired
    private JT_8702Service jt_8702Service;

    /**
     * 查询司机上下线记录
     *
     * @param body
     * @param page
     * @return
     */
    @Auth
    @RequestMapping(value = "list")
    public PayloadBean selectAllRecordByCondition(@RequestBody(required = false) JSONObject body, @RequestBody(required = false) PageBean page) {
        String userId = body.getString("userId");
        int status = body.getInteger("status") == null ? 0 : body.getInteger("status");
        String beginTime = body.getString("beginTime");
        String endTime = body.getString("endTime");
        String driver = body.getString("driver");
        String org_name = body.getString("org_name");
        try {
            List<Map> list = jt_8702Service.selectAllRecordByCondition(userId, status, beginTime, endTime, driver, org_name, page);
            return buildResponseWithPage(list, page);
        } catch (IllegalArgumentException e) {
            return buildResponseWithPage(null, page, setError(0, e.getMessage()));
        }
    }


}
